package org.rency.mq.kafka.consumer.handler.notify;

import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.rency.mq.kafka.consumer.handler.AbstractMessageHandler;
import org.rency.mq.kafka.consumer.support.listener.KafkaBatchMessageListener;
import org.springframework.kafka.listener.AbstractMessageListenerContainer;
import org.springframework.kafka.listener.KafkaDataListener;

import java.util.Arrays;
import java.util.List;

/**
 * 批量消息处理
 *
 * @author: Created by user_rcy@163.com on 2016/10/21.
 * @version: V1.0.0
 * @since JDK 1.8
 */
public abstract class AbstractBatchNotifyHandler<K, V> extends AbstractMessageHandler<K, V> implements NotifyHandler<K, V>{

    @Override
    public KafkaDataListener getMessageListener() {
        return new KafkaBatchMessageListener<K, V>();
    }

    @Override
    public AbstractMessageListenerContainer.AckMode getAckMode() {
        return AbstractMessageListenerContainer.AckMode.BATCH;
    }

    @Override
    public void handler(ConsumerRecord<K, V> data) {
        logger.warn("Kafka Consumer Listener Message Handler Error!");
        this.handler(Arrays.asList(data));
    }

    @Override
    public void handler(List<ConsumerRecord<K, V>> datas) {

    }
}